    var AutoCloseTips = setTimeout(function() {},1);
$(window).scroll(function() {
    var n = $(window).scrollTop();
    // n >= 200 ? $(".scroll-to-top").addClass("active") : $(".scroll-to-top").removeClass("active")
    n >= 200 ? $(".scroll-to-top").show() : $(".scroll-to-top").hide();
});
;(function () {
    $(".scroll-to-top").click(function(){return $("html, body").animate({scrollTop:0},200),!1});
    //全局ajax处理
    $.ajaxSetup({
        complete: function (jqXHR) {
        },
        data: {},
        error: function (jqXHR, textStatus, errorThrown) {
            //请求失败处理
        }
    });

    if ($.browser && $.browser.msie) {
        //ie 都不缓存
        $.ajaxSetup({
            cache: false
        });
    }

    //不支持placeholder浏览器下对placeholder进行处理
    if (document.createElement('input').placeholder !== '') {
        $('[placeholder]').focus(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(function () {
            var input = $(this);
            if (input.val() == '' || input.val() == input.attr('placeholder')) {
                input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur().parents('form').submit(function () {
            $(this).find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        });
    }

    // 所有加了dialog类名的a链接，自动弹出它的href
    if ($('a.js-dialog').length) {
        Wind.css('artDialog');
        Wind.use('artDialog', 'iframeTools', function () {
            $('.js-dialog').on('click', function (e) {
                e.preventDefault();
                var $this = $(this);
                art.dialog.open($(this).prop('href'), {
                    close: function () {
                        $this.focus(); // 关闭时让触发弹窗的元素获取焦点
                        return true;
                    },
                    title: $this.prop('title')
                });
            }).attr('role', 'button');

        });
    }

    // 所有的ajax form提交,由于大多业务逻辑都是一样的，故统一处理
    var ajaxForm_list = $('form.js-ajax-form');
    if (ajaxForm_list.length) {
        Wind.css('artDialog');
        Wind.use('ajaxForm', 'artDialog', 'noty3', 'validate','layer', function () {
            var $btn;
            $('button.js-ajax-submit').on('click', function (e) {
                var btn = $(this), form = btn.parents('form.js-ajax-form');
                $btn    = btn;
                if (btn.data("loading")) {
                    return;
                }
                //批量操作 判断选项
                if (btn.data('subcheck')) {
                    // btn.parent().find('span.tips_error').remove();
                    if (form.find('input.js-check:checked').length) {
                        btn.data('subcheck', false);
                    } else {
                        // $('<span class="tips_error">请选择您要操作的数据！</span>').appendTo(btn.parent()).fadeIn('fast');
                        layer.msg('请选择您要操作的数据！');
                        return false;
                    }
                }


                var msg = btn.data('msg');
                if (msg) {
                    // art.dialog({
                    //     id: 'warning',
                    //     icon: 'warning',
                    //     content: btn.data('msg'),
                    //     cancelVal: '关闭',
                    //     cancel: function () {
                    //         //btn.data('subcheck', false);
                    //         //btn.click();
                    //     },
                    //     ok: function () {
                    //         btn.data('msg', false);
                    //         btn.click();
                    //     }
                    // });

                    layer.confirm(btn.data('msg'), {
                        title:'消息',
                        icon: 0,
                        btn: ['确定','关闭'] //可以无限个按钮
                    }, function(index, layero){
                        btn.data('msg', false);
                        btn.click();
                    }, function(index, layero){
                        layer.close(index);  
                    });

                    return false;
                }

                //ie处理placeholder提交问题
                if ($.browser && $.browser.msie) {
                    form.find('[placeholder]').each(function () {
                        var input = $(this);
                        if (input.val() == input.attr('placeholder')) {
                            input.val('');
                        }
                    });
                }
            });

            ajaxForm_list.each(function () {
                $(this).validate({
                    //是否在获取焦点时验证
                    //onfocusout : false,
                    //是否在敲击键盘时验证
                    //onkeyup : false,
                    //当鼠标点击时验证
                    //onclick : false,
                    //给未通过验证的元素加效果,闪烁等
                    highlight: function (element, errorClass, validClass) {
                        if (element.type === "radio") {
                            this.findByName(element.name).addClass(errorClass).removeClass(validClass);
                        } else {
                            var $element = $(element);
                            $element.addClass(errorClass).removeClass(validClass);
                            $element.parent().addClass("has-error");//bootstrap3表单
                            $element.parents('.control-group').addClass("error");//bootstrap2表单

                        }
                    },
                    unhighlight: function (element, errorClass, validClass) {
                        if (element.type === "radio") {
                            this.findByName(element.name).removeClass(errorClass).addClass(validClass);
                        } else {
                            var $element = $(element);
                            $element.removeClass(errorClass).addClass(validClass);
                            $element.parent().removeClass("has-error");//bootstrap3表单
                            $element.parents('.control-group').removeClass("error");//bootstrap2表单
                        }
                    },
                    showErrors: function (errorMap, errorArr) {
                        var i, elements, error;
                        for (i = 0; this.errorList[i]; i++) {
                            error = this.errorList[i];
                            if (this.settings.highlight) {
                                this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
                            }
                            //this.showLabel( error.element, error.message );
                        }
                        if (this.errorList.length) {
                            //this.toShow = this.toShow.add( this.containers );
                        }
                        if (this.settings.success) {
                            for (i = 0; this.successList[i]; i++) {
                                //this.showLabel( this.successList[ i ] );
                            }
                        }
                        if (this.settings.unhighlight) {
                            for (i = 0, elements = this.validElements(); elements[i]; i++) {
                                this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
                            }
                        }
                        this.toHide = this.toHide.not(this.toShow);
                        this.hideErrors();
                        this.addWrapper(this.toShow).show();
                    },
                    submitHandler: function (form) {
                        var $form = $(form);
                        $form.ajaxSubmit({
                            url: $btn.data('action') ? $btn.data('action') : $form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                            dataType: 'json',
                            beforeSubmit: function (arr, $form, options) {

                                $btn.data("loading", true);
                                var text = $btn.text();

                                //按钮文案、状态修改
                                $btn.text(text + '中...').prop('disabled', true).addClass('disabled');
                            },
                            success: function (data, statusText, xhr, $form) {

                                function _refresh() {
                                    if (data.url) {
                                        //返回带跳转地址
                                        window.location.href = data.url;
                                    } else {
                                        if (data.code == 1) {
                                            //刷新当前页
                                            reloadPage(window);
                                        }
                                    }
                                }

                                var text = $btn.text();

                                //按钮文案、状态修改
                                $btn.removeClass('disabled').prop('disabled', false).text(text.replace('中...', '')).parent().find('span').remove();
                                if (data.code == 1) {
                                    if ($btn.data('success')) {
                                        var successCallback = $btn.data('success');
                                        window[successCallback](data, statusText, xhr, $form);
                                        return;
                                    }
                                    // new Noty({
                                    //     text: data.msg,
                                    //     type: 'success',
                                    //     layout: 'topCenter',
                                    //     modal: true,
                                    //     animation: {
                                    //         open: 'animated bounceInDown', // Animate.css class names
                                    //         close: 'animated bounceOutUp', // Animate.css class names
                                    //     },
                                    //     timeout: 1000,
                                    //     callbacks: {
                                    //         afterClose: function () {
                                    //             if ($btn.data('refresh') == undefined || $btn.data('refresh')) {
                                    //                 _refresh();
                                    //             }
                                    //         }
                                    //     }
                                    // }).show();

                                    layer.msg(data.msg, {
                                        icon: 1,
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    }, function(){
                                        if ($btn.data('refresh') == undefined || $btn.data('refresh')) {
                                            _refresh();
                                        }
                                    });

                                    $(window).focus();
                                } else if (data.code == 0) {
                                    var $verify_img = $form.find(".verify_img");
                                    if ($verify_img.length) {
                                        $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
                                    }

                                    var $verify_input = $form.find("[name='captcha']");
                                    $verify_input.val("");

                                    //$('<span class="tips_error">' + data.msg + '</span>').appendTo($btn.parent()).fadeIn('fast');
                                    $btn.removeProp('disabled').removeClass('disabled');

                                    // new Noty({
                                    //     text: data.msg,
                                    //     type: 'error',
                                    //     layout: 'topCenter',
                                    //     modal: true,
                                    //     animation: {
                                    //         open: 'animated bounceInDown', // Animate.css class names
                                    //         close: 'animated bounceOutUp', // Animate.css class names
                                    //     },
                                    //     timeout: 1500,
                                    //     callbacks: {
                                    //         afterClose: function () {
                                    //             _refresh();
                                    //         }
                                    //     }
                                    // }).show();

                                    layer.msg(data.msg, {
                                        icon: 2,
                                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                    }, function(){
                                        _refresh();
                                    });

                                    $(window).focus();
                                }


                            },
                            error: function (xhr, e, statusText) {
                                art.dialog({
                                    id: 'warning',
                                    icon: 'warning',
                                    content: statusText,
                                    cancelVal: '关闭',
                                    cancel: function () {
                                        reloadPage(window);
                                    },
                                    ok: function () {
                                        reloadPage(window);
                                    }
                                });

                            },
                            complete: function () {
                                $btn.data("loading", false);
                            }
                        });
                    }
                });
            });

        });
    }

    //dialog弹窗内的关闭方法
    $('#js-dialog-close').on('click', function (e) {
        e.preventDefault();
        try {
            art.dialog.close();
        } catch (err) {
            Wind.css('artDialog');
            Wind.use('artDialog', 'iframeTools', function () {
                art.dialog.close();
            });
        }
        ;
    });

    //所有的删除操作，删除数据后刷新页面
    if ($('a.js-ajax-delete').length) {
        Wind.css('artDialog');
        Wind.use('artDialog', 'noty3','layer', function () {
            $('.js-ajax-delete').on('click', function (e) {
                e.preventDefault();
                var $_this  = this,
                    $this   = $($_this),
                    href    = $this.data('href'),
                    refresh = $this.data('refresh'),
                    msg     = $this.data('msg');
                href        = href ? href : $this.attr('href');

                art.dialog({
                    title: false,
                    icon: 'question',
                    content: msg ? msg : '确定要删除吗？',
                    follow: $_this,
                    close: function () {
                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                        return true;
                    },
                    okVal: "确定",
                    ok: function () {
                        $.getJSON(href).done(function (data) {
                            console.log(data);
                            if (data.code == '1') {
                                // new Noty({
                                //     text: data.msg,
                                //     type: 'success',
                                //     layout: 'topCenter',
                                //     modal: true,
                                //     animation: {
                                //         open: 'animated bounceInDown', // Animate.css class names
                                //         close: 'animated bounceOutUp', // Animate.css class names
                                //     },
                                //     timeout: 1,
                                //     callbacks: {
                                //         afterClose: function () {
                                //             if (refresh == undefined || refresh) {
                                //                 if (data.url) {
                                //                     //返回带跳转地址
                                //                     window.location.href = data.url;
                                //                 } else {
                                //                     //刷新当前页
                                //                     reloadPage(window);
                                //                 }
                                //             }
                                //         }
                                //     }
                                // }).show();

                                layer.msg(data.msg, {
                                    icon: 1,
                                    time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    if (refresh == undefined || refresh) {
                                        if (data.url) {
                                            //返回带跳转地址
                                            window.location.href = data.url;
                                        } else {
                                            //刷新当前页
                                            reloadPage(window);
                                        }
                                    }
                                });
                            } else if (data.code == '0') {
                                // art.dialog({
                                //     content: data.msg,
                                //     icon: 'warning',
                                //     ok: function () {
                                //         this.title(data.msg);
                                //         return true;
                                //     }
                                // });
                                
                                layer.confirm(data.msg, {
                                    title:'消息',
                                    icon: 0,
                                    btn: ['确定'] //可以无限个按钮
                                }, function(index, layero){
                                    layer.close(index);  
                                });
                            }
                        });
                    },
                    cancelVal: '关闭',
                    cancel: true
                });
            });

        });
    }
    //会议通过审核
    if ($('a.js-ajax-shenhe').length) {
        Wind.css('artDialog');
        Wind.use('artDialog', 'noty3','layer', function () {
            $('.js-ajax-shenhe').on('click', function (e) {
                e.preventDefault();
                var $_this  = this,
                    $this   = $($_this),
                    href    = $this.data('href'),
                    refresh = $this.data('refresh'),
                    msg     = $this.data('msg');
                href        = href ? href : $this.attr('href');

                art.dialog({
                    title: false,
                    icon: 'question',
                    content: msg ? msg : '确定要更新吗？',
                    follow: $_this,
                    close: function () {
                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                        return true;
                    },
                    okVal: "确定",
                    ok: function () {
                        alert('请稍后');
                        $.getJSON(href).done(function (data) {
                            console.log(data);
                            if (data.code == '1') {
                                // new Noty({
                                //     text: data.msg,
                                //     type: 'success',
                                //     layout: 'topCenter',
                                //     modal: true,
                                //     animation: {
                                //         open: 'animated bounceInDown', // Animate.css class names
                                //         close: 'animated bounceOutUp', // Animate.css class names
                                //     },
                                //     timeout: 1,
                                //     callbacks: {
                                //         afterClose: function () {
                                //             if (refresh == undefined || refresh) {
                                //                 if (data.url) {
                                //                     //返回带跳转地址
                                //                     window.location.href = data.url;
                                //                 } else {
                                //                     //刷新当前页
                                //                     reloadPage(window);
                                //                 }
                                //             }
                                //         }
                                //     }
                                // }).show();

                                layer.msg(data.msg, {
                                    icon: 1,
                                    time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    if (refresh == undefined || refresh) {
                                        if (data.url) {
                                            //返回带跳转地址
                                            window.location.href = data.url;
                                        } else {
                                            //刷新当前页
                                            reloadPage(window);
                                        }
                                    }
                                });
                            } else if (data.code == '0') {
                                // art.dialog({
                                //     content: data.msg,
                                //     icon: 'warning',
                                //     ok: function () {
                                //         this.title(data.msg);
                                //         return true;
                                //     }
                                // });
                                
                                layer.confirm(data.msg, {
                                    title:'消息',
                                    icon: 0,
                                    btn: ['确定'] //可以无限个按钮
                                }, function(index, layero){
                                    layer.close(index);  
                                });
                            }
                        });
                    },
                    cancelVal: '关闭',
                    cancel: true
                });
            });

        });
    }

    // ajax请求
    if ($('a.js-ajax-dialog-btn').length) {
        Wind.use('artDialog', 'noty3', function () {
            $('.js-ajax-dialog-btn').on('click', function (e) {
                e.preventDefault();
                var $_this  = this,
                    $this   = $($_this),
                    href    = $this.data('href'),
                    refresh = $this.data('refresh'),
                    msg     = $this.data('msg');
                href        = href ? href : $this.attr('href');
                if (!msg) {
                    msg = "您确定要进行此操作吗？";
                }
                art.dialog({
                    title: false,
                    icon: 'question',
                    content: msg,
                    follow: $_this,
                    close: function () {
                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                        return true;
                    },
                    ok: function () {

                        $.ajax({
                            url: href,
                            type: 'post',
                            success: function (data) {
                                if (data.code == 1) {
                                    // new Noty({
                                    //     text: data.msg,
                                    //     type: 'success',
                                    //     layout: 'topCenter',
                                    //     modal: true,
                                    //     animation: {
                                    //         open: 'animated bounceInDown', // Animate.css class names
                                    //         close: 'animated bounceOutUp', // Animate.css class names
                                    //     },
                                    //     timeout: 1,
                                    //     callbacks: {
                                    //         afterClose: function () {
                                    //             if (refresh == undefined || refresh) {
                                    //                 if (data.url) {
                                    //                     //返回带跳转地址
                                    //                     window.location.href = data.url;
                                    //                 } else {
                                    //                     //刷新当前页
                                    //                     reloadPage(window);
                                    //                 }
                                    //             }
                                    //         }
                                    //     }
                                    // }).show();

                                    layer.msg(data.msg, {
                                        icon: 1,
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    }, function(){
                                        if (refresh == undefined || refresh) {
                                            if (data.url) {
                                                //返回带跳转地址
                                                window.location.href = data.url;
                                            } else {
                                                //刷新当前页
                                                reloadPage(window);
                                            }
                                        }
                                    });
                                } else if (data.code == 0) {
                                    // art.dialog({
                                    //     content: data.msg,
                                    //     icon: 'warning',
                                    //     ok: function () {
                                    //         this.title(data.msg);
                                    //         return true;
                                    //     }
                                    // });

                                    layer.confirm(data.msg, {
                                        title:'消息',
                                        icon: 0,
                                        btn: ['确定'] //可以无限个按钮
                                    }, function(index, layero){
                                        layer.close(index);  
                                    });
                                }
                            }
                        })
                    },
                    cancelVal: '关闭',
                    cancel: true
                });
            });

        });
    }

    /*复选框全选(支持多个，纵横双控全选)。
     *实例：版块编辑-权限相关（双控），验证机制-验证策略（单控）
     *说明：
     *	"js-check"的"data-xid"对应其左侧"js-check-all"的"data-checklist"；
     *	"js-check"的"data-yid"对应其上方"js-check-all"的"data-checklist"；
     *	全选框的"data-direction"代表其控制的全选方向(x或y)；
     *	"js-check-wrap"同一块全选操作区域的父标签class，多个调用考虑
     */

    if ($('.js-check-wrap').length) {
        var total_check_all = $('input.js-check-all');

        //遍历所有全选框
        $.each(total_check_all, function () {
            var check_all = $(this),
                check_items;

            //分组各纵横项
            var check_all_direction = check_all.data('direction');
            check_items             = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled");

            //点击全选框
            check_all.change(function (e) {
                var check_wrap = check_all.parents('.js-check-wrap'); //当前操作区域所有复选框的父标签（重用考虑）

                if ($(this).prop('checked')) {
                    //全选状态
                    check_items.prop('checked', true);

                    //所有项都被选中
                    if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) {
                        check_wrap.find(total_check_all).prop('checked', true);
                    }

                } else {
                    //非全选状态
                    check_items.removeProp('checked');

                    check_wrap.find(total_check_all).removeProp('checked');

                    //另一方向的全选框取消全选状态
                    var direction_invert = check_all_direction === 'x' ? 'y' : 'x';
                    check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked');
                }

            });

            //点击非全选时判断是否全部勾选
            check_items.change(function () {

                if ($(this).prop('checked')) {

                    if (check_items.filter(':checked').length === check_items.length) {
                        //已选择和未选择的复选框数相等
                        check_all.prop('checked', true);
                    }

                } else {
                    check_all.removeProp('checked');
                }

            });


        });

    }

    //layui日期选择器
    var layuiDateInput = $("input.js-layui-date");
    if (layuiDateInput.length) {
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            lay('.js-layui-date').each(function(){
                laydate.render({
                    elem: this
                });
            });
        });
    }

    //layui日期+时间选择器
    var layuiDateInput = $("input.js-layui-datetime");
    if (layuiDateInput.length) {
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            lay('.js-layui-datetime').each(function(){
                laydate.render({
                    elem: this,
                    type:'datetime'
                });
            });
        });
    }

    //日期选择器
    var dateInput = $("input.js-date");
    if (dateInput.length) {
        Wind.use('datePicker', function () {
            dateInput.datePicker();
        });
    }

    //日期+时间选择器
    var dateTimeInput = $("input.js-datetime");
    if (dateTimeInput.length) {
        Wind.use('datePicker', function () {
            dateTimeInput.datePicker({
                time: true,
                selectors:false,
            });
        });
    }

    var yearInput = $("input.js-year");
    if (yearInput.length) {
        Wind.use('datePicker', function () {
            yearInput.datePicker({
                startView: 'decade',
                minView: 'decade',
                format: 'yyyy',
                autoclose: true
            });
        });
    }

    // bootstrap日期选择器
    var bootstrapDateInput = $("input.js-bootstrap-date")
    if (bootstrapDateInput.length) {
        Wind.css('bootstrapDatetimePicker');
        Wind.use('bootstrapDatetimePicker', function () {
            bootstrapDateInput.datetimepicker({
                language: 'zh-CN',
                format: 'yyyy-mm-dd',
                minView: 'month',
                todayBtn: 1,
                autoclose: true
            });
        });
    }

    // bootstrap日期选择器日期+时间选择器
    var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
    if (bootstrapDateTimeInput.length) {
        Wind.css('bootstrapDatetimePicker');
        Wind.use('bootstrapDatetimePicker', function () {
            bootstrapDateTimeInput.datetimepicker({
                language: 'zh-CN',
                format: 'yyyy-mm-dd hh:ii',
                todayBtn: 1,
                autoclose: true
            });
        });
    }

    // bootstrap日期选择器日期+时间选择器
    var bootstrapTimeInput = $("input.js-bootstrap-time");
    if (bootstrapTimeInput.length) {
        Wind.css('bootstrapDatetimePicker');
        Wind.use('bootstrapDatetimePicker', function () {
            bootstrapTimeInput.datetimepicker({
                startView:1,
                language: 'zh-CN',
                format: 'hh:ii',
                maxView: 'day',
                startDate:'2018-01-18',
                endDate:'2018-01-18 23:59:59',
                // minView: 'hours',
                // todayBtn: 1,     //关闭选择今天时间
                // showMeridian
                autoclose: true
            });
        });
    }


    //tab
    var tabs_nav = $('ul.js-tabs-nav');
    if (tabs_nav.length) {
        Wind.use('tabs', function () {
            tabs_nav.tabs('.js-tabs-content > div');
        });
    }

    //地址联动
    var $js_address_select = $('.js-address-select');
    if ($js_address_select.length > 0) {
        $('.js-address-province-select,.js-address-city-select').change(function () {
            var $this                   = $(this);
            var id                      = $this.val();
            var $child_area_select;
            var $this_js_address_select = $this.parents('.js-address-select');
            if ($this.is('.js-address-province-select')) {
                $child_area_select = $this_js_address_select.find('.js-address-city-select');
                $this_js_address_select.find('.js-address-district-select').hide();
            } else {
                $child_area_select = $this_js_address_select.find('.js-address-district-select');
            }

            var empty_option = '<option class="js-address-empty-option" value="">' + $child_area_select.find('.js-address-empty-option').text() + '</option>';
            $child_area_select.html(empty_option);

            var child_area_html = $this.data('childarea' + id);
            if (child_area_html) {
                $child_area_select.show();
                $child_area_select.html(child_area_html);
                return;
            }

            $.ajax({
                url: $this_js_address_select.data('url'),
                type: 'POST',
                dataType: 'JSON',
                data: {id: id},
                success: function (data) {
                    if (data.code == 1) {
                        if (data.data.areas.length > 0) {
                            var html = [empty_option];

                            $.each(data.data.areas, function (i, area) {
                                var area_html = '<option value="[id]">[name]</option>';
                                area_html     = area_html.replace('[name]', area.name);
                                area_html     = area_html.replace('[id]', area.id);
                                html.push(area_html);
                            });
                            html = html.join('', html);
                            $this.data('childarea' + id, html);
                            $child_area_select.html(html);
                            $child_area_select.show();
                        } else {
                            $child_area_select.hide();

                        }
                    }
                },
                error: function () {

                },
                complete: function () {

                }
            });
        });

    }
    //地址联动end

    $('.list-group .list-group-item').click(function(){
        $(this).siblings().removeClass('on');
        $(this).addClass('on');
    });

})();

//重新刷新页面，使用location.reload()有可能导致重新提交
function reloadPage(win) {
    var location  = win.location;
    location.href = location.pathname + location.search;
}

/**
 * 页面跳转
 * @param url 要打开的页面地址
 */
function redirect(url) {
    location.href = url;
}

/**
 * 读取cookie
 * @param name
 * @returns
 */
function getCookie(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}

/**
 * 设置cookie
 */
function setCookie(name, value, options) {
    options = options || {};
    if (value === null) {
        value           = '';
        options.expires = -1;
    }
    var expires = '';
    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
        var date;
        if (typeof options.expires == 'number') {
            date = new Date();
            date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
        } else {
            date = options.expires;
        }
        expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
    }
    var path        = options.path ? '; path=' + options.path : '';
    var domain      = options.domain ? '; domain=' + options.domain : '';
    var secure      = options.secure ? '; secure' : '';
    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}

/**
 * 打开iframe式的窗口对话框
 * @param url
 * @param title
 * @param options
 */
function openIframeDialog(url, title, options) {
    Wind.css('artDialog');
    var params = {
        title: title,
        lock: true,
        opacity: 0,
        width: "95%",
        height: '90%'
    };
    params     = options ? $.extend(params, options) : params;
    Wind.use('artDialog', 'iframeTools', function () {
        art.dialog.open(url, params);
    });
}

/**
 * 打开地图对话框
 *
 * @param url
 * @param title
 * @param options
 * @param callback
 */
function openMapDialog(url, title, options, callback) {
    Wind.css('artDialog');
    var params = {
        title: title,
        lock: true,
        opacity: 0,
        width: "95%",
        height: 400,
        ok: function () {
            if (callback) {
                var d            = this.iframe.contentWindow;
                var lng          = $("#lng_input", d.document).val();
                var lat          = $("#lat_input", d.document).val();
                var address      = {};
                address.address  = $("#address_input", d.document).val();
                address.province = $("#province_input", d.document).val();
                address.city     = $("#city_input", d.document).val();
                address.district = $("#district_input", d.document).val();
                callback.apply(this, [lng, lat, address]);
            }
        }
    };
    params     = options ? $.extend(params, options) : params;
    console.log(params);
    Wind.use('artDialog', 'iframeTools', function () {
        art.dialog.open(url, params);
    });
}
/**
 * 百度地图获取地址坐标信息
 * @param title 地图对话框标题
 * @param options 额外参数，object,宽度高度等
 * 调用示例：
 *     <a href="javascript:parent.baiduMap('地址', {width:'600px',height:'500px'});">获取坐标</a>
 *     
 */
function baiduMap(title, options) {
    url = GV.ROOT + 'admin/Dialog/map';
    openMapDialog(url,title,options,function(lng,lat,address){
        console.log(lng);
        console.log(lat);
        console.log(address);
    })
}

/**
 * 打开文件上传对话框
 * @param dialog_title 对话框标题
 * @param callback 回调方法，参数有（当前dialog对象，选择的文件数组，你设置的extra_params）
 * @param extra_params 额外参数，object
 * @param multi 是否可以多选
 * @param filetype 文件类型，image,video,audio,file
 * @param app  应用名，CMF的应用名
 */
function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) {
 
    Wind.css('artDialog');
    multi      = multi ? 1 : 0;
    filetype   = filetype ? filetype : 'image';
    app        = app ? app : GV.APP;
    var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app ;
    Wind.use("artDialog", "iframeTools", function () {
        art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
            title: dialog_title,
            id: new Date().getTime(),
            width: '800px',
            height: '500px',
            lock: true,
            fixed: true,
            background: "#CCCCCC",
            opacity: 0,
            ok: function () {
                if (typeof callback == 'function') {
                    var iframewindow = this.iframe.contentWindow;
                    var files        = iframewindow.get_selected_files();
                    
                    var idPre = 'id' + new Date().getTime();
                    $(iframewindow.document).find('.file-item-open').each(function(){
                        var name     = $(this).find('.name').val();
                        var url      = $(this).find('.url').val();
                        var filepath = $(this).find('.filepath').val();

                        var file         = new Object();
                        file.id          = idPre + $(this).index();
                        file.filepath    = filepath;
                        file.preview_url = url;
                        file.url         = url;
                        file.name        = name;
                        if (file.url != undefined && file.url != '') {
                            files.push(file);
                        }
                    });

                    if (files && files.length > 0) {
                        callback.apply(this, [this, files, extra_params]);
                    } else {
                        return false;
                    }
                }
            },
            cancel: true
        });
    });
}


/**
 * 打开文件上传对话框
 * @param dialog_title 对话框标题
 * @param callback 回调方法，参数有（当前dialog对象，选择的文件数组，你设置的extra_params）
 * @param extra_params 额外参数，object
 * @param multi 是否可以多选
 * @param filetype 文件类型，image,video,audio,file
 * @param app  应用名，CMF的应用名
 */
function openUploadWaterDialog(dialog_title, callback, extra_params, multi, filetype, app) {
    Wind.css('artDialog');
    multi      = multi ? 1 : 0;
    filetype   = filetype ? filetype : 'image';
    app        = app ? app : GV.APP;
    var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app +'&water=1';
    Wind.use("artDialog", "iframeTools", function () {
        art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
            title: dialog_title,
            id: new Date().getTime(),
            width: '600px',
            height: '350px',
            lock: true,
            fixed: true,
            background: "#CCCCCC",
            opacity: 0,
            ok: function () {
                if (typeof callback == 'function') {
                    var iframewindow = this.iframe.contentWindow;
                    var files        = iframewindow.get_selected_files();
                    
                    $(iframewindow.document).find('.file-item-open').each(function(){
                        var file_urls  = $(this).find('.hid_url').val();
                        var file_names = $(this).find('.hid_name').html();
                        var now_time   = new Date().getTime()+$(this).index();
                        var addfile = {'id':'id'+now_time,'filepath':file_urls,'name':file_names,'preview_url':file_urls,'url':file_urls};

                        if(files && files.length > 0){
                            [files][0].push(addfile);
                        }
                    });

                    if (files && files.length > 0) {
                        var files = [files][0];
                        for(var i in files){
                            if(files[i].filepath == '' && files[i].url == ''){
                                files.splice(i,1);
                            }
                        }
                      
                        callback.apply(this, [this, files, extra_params]);

                    } else {
                        return false;
                    }
                }
            },
            cancel: true
        });
    });
}

/**
 * 单个文件上传
 * @param dialog_title 上传对话框标题
 * @param input_selector 图片容器
 * @param filetype 文件类型，image,video,audio,file
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF的应用名
 */
function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
    openUploadDialog(dialog_title, function (dialog, files) {
        $(input_selector).val(files[0].filepath);
        $(input_selector + '-preview').attr('href', files[0].preview_url);
        $(input_selector + '-name').val(files[0].name);
    }, extra_params, 0, filetype, app);
}

/**
 * 单个图片上传
 * @param dialog_title 上传对话框标题
 * @param input_selector 图片容器
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF的应用名
 */
function uploadOneImage(dialog_title, input_selector, extra_params, app) {
    openUploadDialog(dialog_title, function (dialog, files) {
        
        $(input_selector).val(files[0].filepath);
        $(input_selector + '-preview').attr('src', files[0].preview_url);
        $(input_selector + '-name').val(files[0].name);
    }, extra_params, 0, 'image', app);
}

/**
 * 水印图片上传
 * @param dialog_title 上传对话框标题
 * @param input_selector 图片容器
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF的应用名
 */
function uploadWaterImage(dialog_title, input_selector, extra_params, app) {
    
    openUploadWaterDialog(dialog_title, function (dialog, files) {
        
        $(input_selector).val(files[0].filepath);
        $(input_selector + '-preview').attr('src', files[0].preview_url);
        $(input_selector + '-name').val(files[0].name);
    }, extra_params, 0, 'image', app);
}

/**
 * 多图上传
 * @param dialog_title 上传对话框标题
 * @param container_selector 图片容器
 * @param item_tpl_wrapper_id 单个图片html模板容器id
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF 的应用名
 */
function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
    openUploadDialog(dialog_title, function (dialog, files) {
        var tpl  = $('#' + item_tpl_wrapper_id).html();
        var html = '';
        $.each(files, function (i, item) {
            var itemtpl = tpl;
            itemtpl     = itemtpl.replace(/\{id\}/g, item.id);
            itemtpl     = itemtpl.replace(/\{url\}/g, item.url);
            itemtpl     = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
            itemtpl     = itemtpl.replace(/\{filepath\}/g, item.filepath);
            itemtpl     = itemtpl.replace(/\{name\}/g, item.name);
            html += itemtpl;
        });
        $(container_selector).append(html);

    }, extra_params, 1, 'image', app);
}


/**
 * 多文件上传
 * @param dialog_title 上传对话框标题
 * @param container_selector 图片容器
 * @param item_tpl_wrapper_id 单个图片html模板容器id
 * @param filetype 文件类型，image,video,audio,file
 * @param extra_params 额外参数，object
 * @param app  应用名,CMF 的应用名
 */
function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app, multi) {
    filetype = filetype ? filetype : 'file';
    multi    = ( multi===0 ) ? 0 : 1;
    openUploadDialog(dialog_title, function (dialog, files) {
        var tpl  = $('#' + item_tpl_wrapper_id).html();
        var html = '';
        $.each(files, function (i, item) {
            var itemtpl = tpl;
            itemtpl     = itemtpl.replace(/\{id\}/g, item.id);
            itemtpl     = itemtpl.replace(/\{url\}/g, item.url);
            itemtpl     = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
            itemtpl     = itemtpl.replace(/\{filepath\}/g, item.filepath);
            itemtpl     = itemtpl.replace(/\{name\}/g, item.name);
            html += itemtpl;
        });
        $(container_selector).append(html);

    }, extra_params, multi, filetype, app);
}


/**
 * 素材库文件上传
 * @param dialog_title  上传对话框标题        srting
 * @param filetype      上传类型：iamge,files srting
 * @param reloads       回调
 * @param upload_type 
 * @param app  应用名,CMF 的应用名
 */
function materialUploadMultiFile(dialog_title, filetype, reloads, upload_type, app) {
    // save_url = $('.pagination').attr('data-title');
    save_url    = '';
    filetype    = filetype ? filetype : 'file';
    upload_type = upload_type ? upload_type : 0;
    
    materiaOpenUploadDialog(dialog_title, function (dialog, files) {
        //判断是否是函数
        if ( typeof(reloads) == 'function' ) {
            //如果是函数，则执行回调函数
            reloads(1);
        }else {
            if (reloads) window.location.reload();
        }
    }, 1, filetype, app, upload_type, save_url);
}


/**
 * 打开文件上传对话框
 * @param dialog_title 对话框标题
 * @param callback 回调方法，参数有（当前dialog对象，选择的文件数组，你设置的extra_params）
 * @param extra_params 额外参数，object
 * @param multi 是否可以多选
 * @param filetype 文件类型，image,video,audio,file
 * @param app  应用名，CMF的应用名
 */
function materiaOpenUploadDialog(dialog_title, callback, multi, filetype, app, upload_type, save_url) {
    Wind.css('artDialog');
    multi      = multi ? 1 : 0;
    filetype   = filetype ? filetype : 'image';
    app        = app ? app : GV.APP;
    var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app + '&upload_type=' + upload_type+ '&save_url=' + save_url+'&no_material=1';
    Wind.use("artDialog", "iframeTools", function () {
        art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
            title: dialog_title,
            id: new Date().getTime(),
            width:  '800px',
            height: '500px',
            lock: true,
            fixed: true,
            background: "#CCCCCC",
            opacity: 0,
            ok: function () {
                // if (typeof callback == 'function') {
                //     var iframewindow = this.iframe.contentWindow;
                //     var files        = iframewindow.get_selected_files();


                //     var sel_file = iframewindow.document.getElementsByClassName("on");
                //     if(sel_file && sel_file.length > 0){
                //         for(var i=0;i<sel_file.length;i++){
                //             var file_urls = sel_file[i].getElementsByClassName("hid_url")[0].value;
                //             var file_names = sel_file[i].getElementsByClassName("hid_name")[0].innerHTML;
                //             var now_time = new Date().getTime()+i;
                //             var addfile = {'id':'id'+now_time,'filepath':file_urls,'name':file_names,'preview_url':file_urls,'url':file_urls};
                //             if(files && files.length > 0){
                //                 [files][0].push(addfile);
                //             }
                //         }
                //     }


                //     if (files && files.length > 0) {
                //         var files = [files][0];
                //         for(var i in files){
                //             if(files[i].filepath == '' && files[i].url == ''){
                //                 files.splice(i,1);
                //             }
                //         }
                      
                //         // callback.apply(this, [this, files, extra_params]);
                //         callback.apply(this, [this, files]);
                //     } else {
                //         // return false;
                //         return true;
                //     }
                // }

                callback.apply(this);
            },
            cancel: true
        });
    });
}

/**
 * 查看图片对话框
 * @param img 图片地址
 */
function imagePreviewDialog(img) {
    Wind.css('layer');

    Wind.use("layer", function () {
        layer.photos({
            photos: {
                "title": "", //相册标题
                "id": 'image_preview', //相册id
                "start": 0, //初始显示的图片序号，默认0
                "data": [   //相册包含的图片，数组格式
                    {
                        "alt": "",
                        "pid": 666, //图片id
                        "src": img, //原图地址
                        "thumb": img //缩略图地址
                    }
                ]
            } //格式见API文档手册页
            , anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机
            shadeClose: true,
            // skin: 'layui-layer-nobg',
            shade: [0.5, '#000000'],
            shadeClose: true,
        })
    });
}

function artdialogAlert(msg) {
    Wind.css('artDialog');
    Wind.use("artDialog", function () {
        art.dialog({
            id: new Date().getTime(),
            icon: "error",
            fixed: true,
            lock: true,
            background: "#CCCCCC",
            opacity: 0,
            content: msg,
            ok: function () {
                return true;
            }
        });
    });

}

function openIframeLayer(url, title, options) {
    var params = {
        type: 2,
        title: title,
        // shadeClose: true,
        // skin: 'layui-layer-nobg',
        anim: -1,
        shade: [0.001, '#000000'],
        shadeClose: true,   //点击遮罩层关闭
        area: ['95%', '90%'],
        content: url,
        // resize:true,        //大小拉伸
        maxmin:true,        //最大最小化
        yes: function (index, layero) {
            //do something
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    };
    params     = options ? $.extend(params, options) : params;

    Wind.css('layer');

    Wind.use("layer", function () {
        // console.log(params);
        layer.open(params);
    });

}

//对列表数据进行排序
function list_sort(sort_by){
    //旧的排序字段和规则
    var old_sort_by = $("input[name='sort_by']").val();
    var sort_order  = $("input[name='list_order']").val();

    //若要排序的字段和旧的一样，则排序规则取反
    if( old_sort_by == sort_by ) sort_order = (sort_order=='DESC') ? 'ASC' : 'DESC' ;
    
    //排序字段和规则重新赋值，用于表单提交刷新页面
    $("input[name='sort_by']").val(sort_by);
    $("input[name='list_order']").val(sort_order);
    $('form.form-search').submit();
}


function get_length(str) {
    ///<summary>获得字符串实际长度，中文2，英文1</summary>
    ///<param name="str">要获得长度的字符串</param>
    var realLength = 0, len = str.length, charCode = -1;
    for (var i = 0; i < len; i++) {
        charCode = str.charCodeAt(i);
    if (charCode >= 0 && charCode <= 128) 
       realLength += 1;
    else
       realLength += 2;
    }
    return realLength;
};

function changeCat(obj)
{
  var key = obj.value;
  // var sel = window.ActiveXObject ? obj.parentNode.childNodes[4] : obj.parentNode.childNodes[5];
  var sel = window.ActiveXObject ? obj.parentNode.childNodes[2] : obj.parentNode.childNodes[3];
  sel.length = 0;
  // sel.options[0] = new Option(sel_filter_attr, 0);
  sel.options[0] = new Option(sel_filter_attr, 0);
  if (arr[key] == undefined)
  {
    return;
  }
  for (var i= 0; i < arr[key].length ;i++ )
  {
    sel.options[i+1] = new Option(arr[key][i][0], arr[key][i][1]);
  }
}
/**
 * 新增一个筛选属性
 */
function addFilterAttr(obj){
    var src = obj.parentNode.parentNode;
    var tbl = document.getElementById('tbody-attr');

    var validator  = new Validator('theForm');
    var filterAttr = document.getElementsByName("filter_attr[]");

    if (filterAttr[filterAttr.length-1].selectedIndex == 0)
    {
        // validator.addErrorMsg(sel_filter_attr);
        
        layer.msg(sel_filter_attr);
        return false;
    }

    for (i = 0; i < filterAttr.length; i++)
    {
        for (j = i + 1; j <filterAttr.length; j++)
        {
          if (filterAttr.item(i).value == filterAttr.item(j).value)
          {
            // validator.addErrorMsg(filter_attr_not_repeated);
            layer.msg(sel_filter_attr);
            return false;
          }
        }
    }

    if (!validator.passed())
    {
        return false;
    }

    var row  = tbl.insertRow(tbl.rows.length);
    var cell = row.insertCell(-1);
    
    cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addFilterAttr)(.*)(\[)(\+)(\])/i, "$1removeFilterAttr$3$4-$6&nbsp;");
    filterAttr[filterAttr.length-1].selectedIndex = 0;
}

/**
* 删除一个筛选属性
*/
function removeFilterAttr(obj)
{
    var row = rowindex(obj.parentNode.parentNode);
    var tbl = document.getElementById('tbody-attr');

    tbl.deleteRow(row);
}

/**
* 切换商品类型
*/
function getAttrList(url,goodsId)
{
    var goodsId = goodsId?goodsId:0;
    var selGoodsType = document.forms['theForm'].elements['post[goods_type]'];

    if (selGoodsType != undefined)
    {
        var goodsType = selGoodsType.options[selGoodsType.selectedIndex].value;

        Ajax.call(url, 'goods_id=' + goodsId + "&goods_type=" + goodsType, setAttrList, "GET", "JSON");
    }
}

function setAttrList(result, text_result)
{
    document.getElementById('tbody-goodsAttr').innerHTML = result.content;
}

//更换模版触发，更换模版演示图片
function changeTemplateImg(id){
    var ele  = $('#'+id);   //元素
    var val  = ele.val();   //元素的值
    var path = '/' + GV.TPL_PATH + "image/";  //模版图片目录所在路径

    var img_path = path + val +'.jpg';  //拼接得到完整的图片路径
    $('#'+id+'-preview').attr('src',img_path);  //替换某个img元素的src
}

function refresh(data) {
    if (data.url) {
        //返回带跳转地址
        window.location.href = data.url;
    } else {
        if (data.code == 1) {
            //刷新当前页
            reloadPage(window);
        }
    }
}

//设置列表项
function setListItem(obj, width, height) {
    var $obj   = $(obj);
    var table_name = $obj.data('table-name');

    var width  = width?width:'400px';
    var height = height?height:'600px';

    parent.openIframeLayer(GV.ROOT + 'admin/list_item/index?table_name='+table_name, '设置列表中显示的字段', {
        area: [width, height],
        btn: ['确定', '取消'],
        //点击确定时触发
        yes: function (index, layero) {
            var iframeWin = parent.window[layero.find('iframe')[0]['name']];
            //提交表单
            iframeWin.confirm();
            parent.layer.close(index);
            reloadPage(window);
        },
        //无论是确认还是取消，只要层被销毁了，end都会执行
        // end: function(){
            //刷新页面
        // }
    });
}



function getFlowData(obj,width,height) {
    var $obj = $(obj);
    var id   = $obj.data('objcet-id');
    var type = $obj.data('type');

    var width  = width?width:'90%';
    var height = height?height:'90%';

    parent.openIframeLayer(GV.ROOT + 'admin/traffic_statistics/index?id='+id+'&type='+type, '访问量统计', {
        area: [width, height],
        btn: ['关闭'],
        //点击确定时触发
        yes: function (index, layero) {
            // var iframeWin = parent.window[layero.find('iframe')[0]['name']];
            //提交表单
            // iframeWin.confirm();
            parent.layer.close(index);
            // reloadPage(window);
        },
        //无论是确认还是取消，只要层被销毁了，end都会执行
        // end: function(){
            //刷新页面
        // }
    });
}

//获取用户上传的资源，素材库
function GetMaterial(href,data,input_selector, loading){
    var input_selector = input_selector ? input_selector : '.asset-data';
    var loading        = loading ? loading : '.loading';

    $(loading).show();
    $.ajax({
        url:  href,
        data: data,
        type: 'get',
        dataType: 'json',
        beforeSend:function(){
        },
        success: function (res) {
            $(input_selector).html(res.html);
            $(loading).hide();
        }
    });
}

// 预览详细内容(文本编辑器)
function contentPreview(container, title_container, time_container){
    // editorcontent
    var title_container = title_container ? title_container : 'title';
    var time_container  = time_container ? time_container : '';
    var title   = $('#'+title_container).val();
    var content = container.getContent();

    var html = '<div class="contentView"><div class="newsText">';
            html+= '<div class="title">';
                html+= '<h1>' + title + '</h1>';
                if( time_container!='' ){
                    var time = $('#'+time_container).val();
                    time = time.substring(0,10);
                    html+= '<div class="time">' + time + '</div>';
                }else{
                    html+='<br>'
                }
            html+= '</div>';
            html+= '<div class="pageMain">'+ content +'</div>';
        html+= '</div></div>';
        
    Wind.use("layer", function () {
        layer.open({
            type: 1,
            anim: 5,
            shade: [0.3, '#000000'],
            resize:true,        //大小拉伸
            maxmin:true,        //最大最小化
            shadeClose: true,   //点击遮罩层关闭
            skin: 'layui-layer-rim-view', //加上边框
            area: ['1100px', '70%'], //宽高
            content: html,
        });
    });
}


//设置列表每页数据条数
function setPageSize(size){
    $("input[name='page_size']").val(size);
    $('form.form-search').submit();
}


function AutoTopTips(n, t, i) {
    var r = "",
    u = "警告！";
    switch (n) {
    case 1:
        r = "alert-success";
        u = " √ ";
        break;
    case 0:
        r = "alert-danger";
        u = " × "
    }
    clearTimeout(AutoCloseTips);
    $("#global_tips").hide().html('<div class="alert ' + r + '"><button type="button" class="close" data-dismiss="alert">&times;<\/button><strong>' + u + "<\/strong>" + t + "<\/div>").fadeIn(1e3);
    
    typeof i == "undefined" && (i = 5e3);
    i > 0 && (AutoCloseTips = setTimeout(function() {
        $("#global_tips").fadeOut(500)
    },
    i))
}


//通用ajax获取数据列表
function ajaxList(urls, callback, datas) {
    //防止经常重复点击发送请求
    if (ajax_config.status == 0) return false;
    ajax_config.status = 0;
    ajax_config.urls = urls;//记录请求地址

    bpop.addLoading();

    $.getJSON(urls, datas, function(data) {
        bpop.clean();
        ajax_config.status = 1;
        if (data.status == 1) {
            //回调函数
            callback(data);
            $('.pages a').click(function(event) {
                event.preventDefault();
                event.stopImmediatePropagation();
                var urls = $(this).attr('href');
                ajaxList(urls, callback, datas);
            });
        }
    });
}


//弹窗函数对象
function bpop() {
    this.speed = 0
}
/**
* 添加弹窗
* info 内容，type类型：(1只有确认)(2确认-取消), callback,默认false
*/
bpop.prototype.add = function(info, type, callback) {
    this.clean();
    var btn = '<span class="btn-item btn-item-red btn-confirm" onclick="bpop.clean('+callback+');">确认</span>';
    btn = type == 2 ? btn = btn + '<span class="btn-item btn-cancel" onclick="bpop.clean();">取消</span>' : btn;
    var html = '<div class="bpop"><div class="bpop-center"><div class="bpop-title">网站提醒</div><div class="bpop-body">'+info+'</div><div class="bpop-btn">'+btn+'</div></div></div><div class="zbodys"></div>';
    $('body').append(html);
    this.fixed();
}
//定位
bpop.prototype.fixed = function() {
    this.center('bpop');
    $('body .bpop').addClass('bpop-css3');
}
//清除
bpop.prototype.clean = function(callback) {
    $('body .bpop').removeClass('bpop-css3');
    $('body .zbodys, body .bpop-load, body .bpop-tip').remove();
    $('body .bpop').fadeOut(function() {
        $(this).remove();
    }, 0);
    //如果存在回调函数则启用
    if (callback) {
        callback();
    }
}
//loading加载
bpop.prototype.addLoading = function(z) {
    this.clean();
    $('body .zbodys, body .bpop, body .bpop-load').remove();
    $('body').append('<div class="bpop-load" />');
    if (z) $('body').append('<div class="zbodys" />');
    this.center('bpop-load');
}
//loading加载
bpop.prototype.parentLoading = function(z) {
    $(window.top.document).find('body .zbodys, body .bpop-load, body .bpop-tip').remove();
    var loads = $('<div class="bpop-load" />');
    $(window.top.document).find('body').append(loads);
    if (z) $(window.top.document).find('body').append('<div class="zbodys" />');
    $(window.top.document).find(loads).css({
        'left' : ($(window.top).width()/2 - $(window.top.document).find(loads).width()/2) + 'px',
        'top' : ($(window.top).height()/2 - $(window.top.document).find(loads).height()/2) + 'px'
    });
}
//tip提醒 1 正确,2提示,3错误
bpop.prototype.tip = function(info, status, times, url, z) {
    clearTimeout(this.speed);
    this.clean();
    $('body .bpop-tip').remove();
    //是否启用遮罩
    var cls = status == 2 ? 't' : status == 3 ? 'n' : '';
    var html = '<div class="bpop-tip"><div class="bpop-tip-center"><span class="bpop-s bpop-'+cls+'"></span><span class="bpop-font">'+info+'</span><div class="bpop-clear"></div></div></div>';
    $('body').append(html);
    if (z) $('body').append('<div class="zbodys" />');
    this.center('bpop-tip');
    //自动关闭
    this.speed = setTimeout(function() {
        if (url) {
            //如果是重载
            if (url == 'load' || url == '?') {
                window.location.reload();
            }else {
                location.href = url;
            }
        }else {
            bpop.clean();
        }
    }, times*1000);
}
//元素居中
bpop.prototype.center = function(cls) {
    $('body .'+cls).css({
        'left' : ($(window).width()/2 - $('body .'+cls).width()/2) + 'px',
        'top' : ($(window).height()/2 - $('body .'+cls).height()/2) + 'px'
    });
}
//创建对象
var bpop = new bpop();


//表单提交，敏感词检测提示，确认替换则提交表单，否则取消
function CheckSenSubmit(href){
    var href = href ? href : GV.ROOT + 'portal/admin_sensitive/replace';;
    var ajaxForm   = $('form.js-ajax-form');
    var is_replace = ajaxForm.attr('data-replace');

    //该表单是否需要敏感词检测
    if( is_replace == '1' ){
        var data     = new Object;
        var arr      = new Array();
        var fieldArr = new Array();

        ajaxForm.find('.form-replace').each(function(){
            var val = '', field = '';
            if( $(this).attr('data-field') ){
                field = $(this).attr('data-field');     //字段名
                val   = $(this).val();                  //值
            }else{
                if( $(this).attr('id') ){
                    field = $(this).attr('id');
                    // name  = field+'.getContent()';    //'content0.getContent()'
                    name  = 'UE.getEditor("'+field+'").getContent()';    //'content0.getContent()'

                    val   = eval(name);                   //执行变量里的字符串(代码方式执行)，获取编辑器内容
                }
            }

            if( val!='' ){
                arr.push(val);
                fieldArr.push(field);
            }
        });

        data.data  = arr;
        data.field = fieldArr;

        $.ajax({
            url: href,  
            type: "POST",  
            data: data,
            dataType: "json",  
            beforeSend:function(){
            },
            success: function (res) {
                // console.log(res);
                // return;
                if(res.error == 1){
                    //询问框
                    Wind.use("layer", function () {
                        layer.confirm(res.html, {
                                title: ['提示信息'],
                                btn: ['确定', '取消'], //按钮
                                area:'auto',
                                maxWidth:'80%',
                            },
                            function(index) {
                                layer.close(index);
                                ajaxSubmit('#js-ajax-submit');
                            }
                        );
                    });
                }else{
                    ajaxSubmit('#js-ajax-submit');
                }
            }
        });
    }else{
        ajaxSubmit('#js-ajax-submit');
    }
}

function ajaxSubmit(id){
    $(id).click();
};

function layer_msg(icon, time){
    Wind.use("layer", function () {
        layer.msg('同上', {
          icon: 1,
          time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
          //do something
        }); 

        layer.msg({
            type: 1,
            anim: 5,
            shade: [0.3, '#000000'],
            resize:true,        //大小拉伸
            maxmin:true,        //最大最小化
            shadeClose: true,   //点击遮罩层关闭
            skin: 'layui-layer-rim-view', //加上边框
            area: ['1100px', '70%'], //宽高
            content: html,
        });
    });
}
